/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DeleteLayerForm.java
 *
 * Created on 23-mei-2011, 12:45:23
 */
package com.iceberg.adgt.ui.gen;

import com.iceberg.adgt.common.ControllerException;
import com.iceberg.adgt.ui.architecture.ArchitectureController;

/**
 * @author Tim Hofman Laptop
 */
class DeleteUnitForm extends javax.swing.JPanel {

	/**
	 * Creates new form DeleteLayerForm
	 */
	public DeleteUnitForm() {
		initComponents();
	}

	/**
	 * This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
	private void initComponents() {

		deleteUnit = new javax.swing.JButton();
		deleteUnitErrorMsg = new javax.swing.JLabel();

		deleteUnit.setText("Delete unit");
		deleteUnit.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				deleteUnitActionPerformed(evt);
			}
		});

		deleteUnitErrorMsg.setForeground(java.awt.Color.red);

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
		this.setLayout(layout);
		layout.setHorizontalGroup(
				layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(layout.createSequentialGroup()
								.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
										.addComponent(deleteUnit)
										.addComponent(deleteUnitErrorMsg))
								.addContainerGap(313, Short.MAX_VALUE))
		);
		layout.setVerticalGroup(
				layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
								.addComponent(deleteUnitErrorMsg, javax.swing.GroupLayout.DEFAULT_SIZE, 14, Short.MAX_VALUE)
								.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addComponent(deleteUnit))
		);
	}// </editor-fold>//GEN-END:initComponents

	private void deleteUnitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteUnitActionPerformed
		try {
			this.controller.removeUnitFromLayer();
			deleteUnitErrorMsg.setText("");
		} catch (ControllerException ex) {
			deleteUnitErrorMsg.setText("There is no unit selected!");
		}


	}//GEN-LAST:event_deleteUnitActionPerformed

	// Variables declaration - do not modify//GEN-BEGIN:variables
	private javax.swing.JButton deleteUnit;
	private javax.swing.JLabel deleteUnitErrorMsg;
	// End of variables declaration//GEN-END:variables
	private ArchitectureController controller;

	public final void setController(ArchitectureController controller) {
		this.controller = controller;
	}
}
